package org.sifebint.backend.services.reportcatalog;

import java.util.List;

import net.jankovar.spring.aspects.InRole;

import org.sifebint.backend.dao.folders.FolderDao;
import org.sifebint.backend.dao.reports.ReportDao;
import org.sifebint.backend.model.Folder;
import org.sifebint.backend.model.Report;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.transaction.annotation.Transactional;

@Transactional
public class ReportCatalogServiceImpl implements ReportCatalogService {
  
  private FolderDao folderDao;
  
  private ReportDao reportDao;
  
  @InRole("sifebint-admin")
  @Override
  public void createFolder(Folder folder) {
    folderDao.createFolder(folder);
  }

  @InRole("sifebint-admin")
  @Override
  public void createReport(long folderId, Report report) {
    reportDao.createReport(folderId, report);
  }

  @InRole("sifebint-admin")
  @Override
  public void deleteFolder(long folderId) {
    folderDao.deleteFolder(folderId);
  }

  @InRole("sifebint-admin")
  @Override
  public void deleteReport(long reportId) {
    reportDao.deleteReport(reportId);
  }

  @InRole("sifebint-user")
  @Override
  public List<Folder> getFoldersWithReports() {
    return folderDao.getFoldersWithReports();
  }

  @InRole("sifebint-admin")
  @Override
  public void moveReport(long reportId, long destinationFolderId) {
    reportDao.moveReport(reportId, destinationFolderId);
  }

  @InRole("sifebint-admin")
  @Override
  public void updateFolder(Folder folder) {
    folderDao.updateFolder(folder);
  }

  @InRole("sifebint-admin")
  @Override
  public void updateReport(Report report) {
    reportDao.updateReport(report);
  }
  
  @Required
  public void setFolderDao(FolderDao folderDao) {
    this.folderDao = folderDao;
  }
  
  @Required
  public void setReportDao(ReportDao reportDao) {
    this.reportDao = reportDao;
  }

}
